package edu.mse.camel.client.playback.actions;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;

import edu.mse.camel.client.playback.Activator;
import edu.mse.camel.client.playback.events.ReceiveGenericPeerEventList;

public class PreviousActionDelegate implements IObjectActionDelegate,
IViewActionDelegate {

	private int index=0;
	
	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void run(IAction action) {
		
		index = ReceiveGenericPeerEventList.getInstance().getCurrentIndex();
		
		if (index < 0){
			ErrorDialog ed = new ErrorDialog(new Shell(),
					"Error",
					"You already reached the start. Unable to rewind.", 
					new Status(
							IStatus.ERROR, Activator.PLUGIN_ID,
							"You already reached the start. Unable to rewind."),
					IStatus.ERROR);
			ed.open();				

		} else {
			ReceiveGenericPeerEventList.getInstance().previousEvent();
		}
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(IViewPart view) {
		// TODO Auto-generated method stub		
	}

}
